home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Tools & Apps / OS⁄Toolbox / Apple Events / AE Word Services 1.0d6 / Writeswell Jr. Source / InitMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-23  |  2.4 KB  |  109 lines  |  [TEXT/KAHL]

  1. /* InitMenu.c
  2.  * ©1992 Working Software, Inc.
  3.  * This source code is copyrighted.  Permission is granted to use the Word Services
  4.  * portion of the Writeswell Jr. source code in your own programs, but you 
  5.  * may not distribute the Writeswell Jr. word-processor code as a 
  6.  * commercial product.  If you modify the code, please do not call it 
  7.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  8.  * program and don’t have to deal with a number of different versions with 
  9.  * who-knows-what going on in the code.
  10.  * 
  11.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  12.  */
  13.  
  14. #include <EPPC.h>
  15. #include <AppleEvents.h>
  16. #include "TBConstants.h"
  17. #include "Prefs.h"
  18. #include "InitMenu.h"
  19. #include "Gripe.h"
  20. #include "TBGlobals.h"
  21.  
  22. void PutUpMenus( void )
  23. {
  24.     Handle myMenuBar;
  25.     MenuHandle appleMenu;
  26.  
  27.     InitMenus();
  28.     
  29.     appleMenu = GetMenu( kAppleMenuID );
  30.     if ( !appleMenu ){
  31.         Gripe( "\pcannot get Apple Menu Handle" );
  32.         return;
  33.     }
  34.  
  35.     AddResMenu( appleMenu, 'DRVR' );
  36.     
  37.     myMenuBar = GetNewMBar( kMBarID );
  38.     if ( !myMenuBar ){
  39.         Gripe( "\pCannot get menu bar" );
  40.         return;
  41.     }
  42.     
  43.     SetMenuBar( myMenuBar );
  44.     DrawMenuBar();
  45.  
  46.     BuildServiceMenu();
  47.         
  48.     return;
  49. }
  50.  
  51. OSErr BuildServiceMenu( void )
  52. {
  53.     WWJrPrefsHdl    prefHdl;
  54.     short            i;
  55.     short            servNum;
  56.     StringHandle    menuStrHdl;
  57.     short            curFile;
  58.     MenuHandle        servMenu;
  59.     short            resID;
  60.  
  61.     prefHdl = GetPrefHandle();
  62.     if ( !prefHdl ){
  63.         Gripe( "\pCannot get preferences handle" );
  64.         return;
  65.     }
  66.  
  67.     CheckSelectMenu( prefHdl );
  68.     
  69.     servMenu = GetServiceMenu();
  70.     if ( !servMenu ){
  71.         Gripe( "\pCannot get service menu handle" );
  72.         return;
  73.     }
  74.  
  75.     curFile = CurResFile();
  76.     UseResFile( gPrefFileRefNum );
  77.  
  78.  
  79.     /* This routine here could be modified to sort the service menu into some
  80.      * order, such as alphabetical, by associating the item numbers with the
  81.      * resource numbers in the desired order.
  82.      */
  83.  
  84.     servNum = 0;
  85.  
  86.     for ( i = 0; i < kMaxServices; i++ ){
  87.         if ( (*prefHdl)->serviceType[ i ] != kNoService ){
  88.         
  89.             resID = kServiceBaseID + i;
  90.  
  91.             menuStrHdl = GetString( resID );
  92.             if ( !menuStrHdl ){
  93.                 Gripe( "\pCannot get string resource for service menu" );
  94.                 UseResFile( curFile );
  95.                 return resNotFound;
  96.             }
  97.             HLock( menuStrHdl );
  98.             AppendMenu( servMenu, *menuStrHdl );    /* Note: this will interpret special chars */
  99.             HUnlock( menuStrHdl );
  100.             ReleaseResource( menuStrHdl );
  101.             
  102.             gServItemID[ servNum++ ] = resID;
  103.             
  104.         }
  105.     }
  106.  
  107.     UseResFile( curFile );
  108.     return noErr;
  109. }